#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll R[2][2001],B[2][2001],a[200001],ans,Rall,Ball,Bmax,Rmax;
int T,n;
bool col[2001];
void dfs(int u){
    if(u>n){
        ll s=0;
        int Rlt=0,Blt=0;
        for(int i=1;i<=n;i++){
            if(col[i]==0){
                if(a[i]==Blt)s+=Blt;
                Blt=a[i];
            }
            else{
                if(a[i]==Rlt)s+=Rlt;
                Rlt=a[i];
            }
        }
        ans=max(ans,s);
        return;
    }
    col[u]=0;
    dfs(u+1);
    col[u]=1;
    dfs(u+1);
}
int main(){
    ios::sync_with_stdio(false);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        ans=0;
        for(int i=1;i<=n;i++)cin>>a[i];
        dfs(1);
        cout<<ans<<endl;
    }
    return 0;
}
